package com.emep.changzhi.analyse.service.information;


import com.emep.changzhi.analyse.entity.information.SysSendeRule;
import com.emep.changzhi.analyse.entity.information.SysWarningRule;
import com.emep.changzhi.analyse.repository.information.SysSendRuleRepository;
import com.emep.changzhi.analyse.repository.information.SysWaringRuleRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class SysSendRuleService {

    @Autowired
    SysSendRuleRepository repository;


    public SysSendeRule add(Map<String, Object> payload) {

        SysSendeRule sysSendeRule = null;
        try {
            SysSendeRule sysSendeRule1 = (SysSendeRule) MapUtils.convertMap(SysSendeRule.class,payload);
            sysSendeRule = repository.save(sysSendeRule1);
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return sysSendeRule;
    }

    public List<SysSendeRule> getList() {

        List<SysSendeRule> sysSendeRuleList = null;
        try {
            sysSendeRuleList =  repository.findAll();
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return sysSendeRuleList;
    }




    public boolean delete(int id) {

        Boolean result = false;
        try {
            repository.deleteById(id);
            result =true;
        }catch (Exception e){
            log.error(e.getLocalizedMessage());
        }
        return result;

    }

}
